package org.bank.model;

import java.io.Serializable;
import javax.persistence.*;

/**
 * Entity implementation class for Entity: Account
 *
 */
//Entity for the account data.
@Entity
public class Account implements Serializable {

	   
	@Id
	private int ID;
	
	private double balance;
	
	@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "PERSON_ID")
	private Person person; //there is a one to one relationship between these two entities.
	
	private static final long serialVersionUID = 1L;
	
	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public int getID() {
		return this.ID;
	}

	public void setID(int ID) {
		this.ID = ID;
	}   
	public double getBalance() {
		return this.balance;
	}

	public void setBalance(double balance) {
		this.balance = balance;
	}
	
	/*//method to get the transfer object for the data of the account
	public AccountTO getAccountData()
	{
		return createAccountTO();
	}
	
	//method to create a new transfer object with the values of this entity bean
	private AccountTO createAccountTO() {
		AccountTO account = new AccountTO();
		account.address = this.address;
		account.balance = this.balance;
		account.firstName = this.firstName;
		account.ID = this.ID;
		account.lastName = this.lastName;
		account.phone = this.phone;
		return account;
	}
	
	//method to set this entity values to those of the transfer object
	public void setAccountData(AccountTO updatedAccount)
	{
		mergeAccountData(updatedAccount);
	}
	
	//method to merge the attributes of the TO with those of the bean
	private void mergeAccountData(AccountTO updatedAccount) {
		this.address = updatedAccount.address;
		this.balance = updatedAccount.balance;
		this.firstName = updatedAccount.firstName;
		this.ID = updatedAccount.ID;
		this.lastName = updatedAccount.lastName;
		this.phone = updatedAccount.phone;
	}*/
   
}
